//Erstellt von Moritz Liepe
package main;

import java.rmi.server.UID;
import java.util.UUID;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;


public class Module extends Figure{
	private String ID;
	private String SIMID;
	private Label title = new Label("");
	private String titleImagePath;
	private boolean selected = false;
	private final Color color = new Color(null,200,200,200);
	private int width, height, initialX, initialY;

	private final XYLayout layout = new XYLayout();
	
	public Module(){
		  this.ID = UUID.randomUUID().toString();
		  
		  this.setLayoutManager(layout);	
		  this.setBorder(new LineBorder(ColorConstants.black,1));
		  this.setBackgroundColor(color);
		  this.setOpaque(true);
		  this.setCursor(new Cursor(null, SWT.CURSOR_HAND));
		   
	}
	
	public Module(String id, int width, int height){
		  this.ID = id;
		  this.width = width;
		  this.height = height;
		  
		  this.setLayoutManager(layout);	
		  this.setBorder(new LineBorder(ColorConstants.black,1));
		  this.setBackgroundColor(color);
		  this.setOpaque(true);
		  this.setCursor(new Cursor(null, SWT.CURSOR_HAND));
		   
	}
	
	public int getInitialX() {
		return initialX;
	}

	public void setInitialX(int initialX) {
		this.initialX = initialX;
	}

	public int getInitialY() {
		return initialY;
	}

	public void setInitialY(int initialY) {
		this.initialY = initialY;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public String getID() {
		return ID;
	}

	public void setID(String iD) {
		ID = iD;
	}
	
	public void generateID() {
		this.ID = new UID().toString();
	}

	public Label getTitle() {
		return this.title;
	}

	public void setTitle(Label title) {
		title.setToolTip(new Label(title.getText()));
		if (this.getChildren().size() > 0)this.getChildren().remove(0);
		this.add(title, new Rectangle(10, 10, this.width-20, 40), 0);
		this.title = title;
	}
	
	public String getTitleImagePath() {
		return titleImagePath;
	}

	public void setTitleImagePath(String titleImagePath) {
		this.titleImagePath = titleImagePath;
	}

	public boolean isSelected(){
		return selected;
	}
	
	public void setSelected(){
		this.setBackgroundColor(ColorConstants.white);
		selected = true;
	}
	
	public void setDeselected(){
		this.setBackgroundColor(color);
		selected = false;
	}
	
	public void addControl(IModuleControl ctrl){
		this.add(ctrl, new Rectangle(ctrl.getX(), ctrl.getY(), ctrl.getWidth(), ctrl.getHeight()));
	}

	public String getSIMID() 
	{
		return SIMID;
	}

	public void setSIMID(String sIMID) 
	{
		SIMID = sIMID;
	}
	
	
}
